/*
 * Author Anju
 */
package com.sdi.columbus;

import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;


public class MainUser extends ListActivity {
	

	Intent intent;
	Bundle bun;
	GpsData gpsData = new GpsData();
	

	 String[] regno=null;
	 String[] vname=null;
//	 int[] vid=new int[gpsData.getSize()];
	 String[] vid=new String[gpsData.getSize()];
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		regno = new String[gpsData.getSize()];
		 vname = new String[gpsData.getSize()];
		 
		 regno=gpsData.getVehicleRegNo();
		 vname=gpsData.getVehicleModel();
		 vid=gpsData.getVehicleIds();
	   
		setListAdapter(new MapData(this,vname));
		
		

	}

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {

		//get selected items
		String selectedValue = (String) getListAdapter().getItem(position);
		//Toast.makeText(this, selectedValue, Toast.LENGTH_SHORT).show();
		int index=position;
//		int ids=vid[index];
		String ids=vid[index];
		
		System.out.println(" Selected Vehicle ID : "+ids);
		
		intent=new Intent(MainUser.this,GMapActivity.class);
		Bundle bundle=new Bundle();
//		bundle.putInt("ID", ids); 
		bundle.putString("ID", ids);
		intent.putExtras(bundle);
		intent.putExtra("GpsData",gpsData);
		new performBackgroundTask().execute();
	}

	
	private class performBackgroundTask extends AsyncTask < Void, Void, Void > 
    {
		
       private ProgressDialog pdia;

       @Override
       protected void onPreExecute(){
          super.onPreExecute();
               pdia = new ProgressDialog(MainUser.this);
               pdia.setMessage("Please Wait....");
               pdia.show();
               System.out.println("In onPreExecute");         
       }
 
       @Override
       protected Void doInBackground(Void... params) {
    	   
    	   System.out.println("In doInBackground");
    	   startActivity(intent);
    	   return null;
    
       }

       @Override
       protected void onPostExecute(Void result) {
    	   super.onPostExecute(result);
    	   System.out.println("In onPostExecute");
    	   pdia.dismiss();
       }

       @Override
       protected void onProgressUpdate(Void... values) {
    	   super.onProgressUpdate(values);
    	   System.out.println("In onProgressUpdate");
       }

    }
}


